//
//  JHSDoctorApplyViewController.m
//  JHSSweep
//  申请名医
//  Created by Apple on 2017/3/23.
//  Copyright © 2017年 JHDS. All rights reserved.
//
#define DOCCELL @"docCell"
#import "JHSDoctorApplyViewController.h"
#import "JHSDoctorListCell.h"
#import "JHSDetailDoctorViewController.h"
#import <MJRefresh.h>
#import "JHSNetworkTool.h"
#import "YYXHorizontalLinkViewController.h"
@interface JHSDoctorApplyViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(strong,nonatomic)NSArray<JHSDoctorListModel *> *DocList;


@end

@implementation JHSDoctorApplyViewController



- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupUI];
}



-(void)setupUI{
    
    [self.tableView registerNib:[UINib nibWithNibName:@"JHSDoctorListCell" bundle:nil] forCellReuseIdentifier:DOCCELL];
    
    //设置行高
    self.tableView.rowHeight = 80;
    
    //MARK: 设置上下拉刷新
    //解决循环引用问题
    __weak typeof(self) weakSelf = self;
    //下拉刷新
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        //刷新指定时间
        [NSThread sleepForTimeInterval:2.0];
        [weakSelf.tableView.mj_header endRefreshing];
        [JHSDoctorApplyViewController jhsShowSVSuccessTitle:@"加载完成" andTime:0.8];
        
    }];
    //上拉刷新
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        //刷新指定时间
        [NSThread sleepForTimeInterval:2.0];
        [weakSelf.tableView.mj_footer endRefreshing];
        [JHSDoctorApplyViewController jhsShowSVSuccessTitle:@"加载完成" andTime:0.8];
    }];
    
    //获取网络数据
    NSString *url = @"http://iosapi.itcast.cn/doctor/matchDoctors.json.php";
    NSDictionary *parameter = @{@"ci1_id":@1,@"ci2_id":@3,@"ci3_id":@3,@"diagnosis_type":@0,@"page_size":@15,@"is_confirmed":@1,@"user_id":@1000089, @"page":@1,@"has_diagnosis":@2};
    
    [JHSDoctorListModel getDoctorListDataWithURLString:url andParameters:parameter andSuccessBlock:^(NSArray *newsList) {
        
        self.DocList = newsList;
        [self.tableView reloadData];
        
    } andErrorBlock:^(NSError *error) {
        
        NSLog(@"error = %@",error);
    }];
}


#pragma mark - 数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.DocList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    JHSDoctorListCell *cell = [tableView dequeueReusableCellWithIdentifier: DOCCELL forIndexPath:indexPath];
    
    cell.doctorModel = self.DocList[indexPath.row];
    
    return cell;
}


//cell的点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (self.isCanClickedCell==0) {
        return;
    }
    
    JHSDoctorListModel *model=self.DocList[indexPath.row];
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"JHSDoctorDetailsStryboard" bundle:nil];
    JHSDetailDoctorViewController *follow = [sb instantiateInitialViewController];
    follow.detailModel=model;
    //点击进行Push
    [self.navigationController pushViewController:follow animated:YES];
    
}

//刷新
+ (void)jhsShowSVSuccessTitle:(NSString *)content andTime:(float)delay{
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD setBackgroundColor:JHSMainColor];
    [SVProgressHUD showSuccessWithStatus:[NSString stringWithFormat:@"%@",content]];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
    });
}




@end
